#include <iostream>
#include <cstring>
using namespace std;
struct stu
{
    string id;
    // int machine_seat;
    int exam_seat;
};

int main()
{
    int N;
    scanf("%d", &N);
    struct stu S[N + 1];
    // struct stu *S = new stu[N];
    string tmp_id;
    int tmp_machine_seat;
    int tmp_exam_seat;
    for (int i = 0; i < N; i++)
    {
        cin >> tmp_id;
        cin >> tmp_machine_seat;
        cin >> tmp_exam_seat;
        S[tmp_machine_seat].id = tmp_id;
        S[tmp_machine_seat].exam_seat = tmp_exam_seat;
    }
    int num;
    cin >> num;
    int stu_id;
    for (int j = 0; j < num; j++)
    {
        cin >> stu_id;
        cout << S[stu_id].id << " " << S[stu_id].exam_seat << endl;
    }

    return 0;
}
/*
4
3310120150912233 2 4
3310120150912119 4 1
3310120150912126 1 3
3310120150912002 3 2
*/